using System.Collections.Generic;

namespace MirrorMirror
{
    public class DelegatesCache 
    {
        private readonly IDictionary<string,object> innerCache = new Dictionary<string, object>();

        private static string GetKeyFor<T>(string key)
        {
            return typeof (T).Description() + "-" + key;
        }
        public bool TryGetValue<T>(string key, out T value)
        {
            object untypedValue;
            
            if (innerCache.TryGetValue(GetKeyFor<T>(key), out untypedValue))
            {
                value = (T)untypedValue;
                return true;
            }

            value = default(T);
            return false;
        }

        public void Add<T>(string key, T value)
        {
            innerCache.Add(GetKeyFor<T>(key), value);
        }

    }
}